import datetime
from haystack import indexes
from haystack import site
from news.models import News


class NewsIndex(indexes.SearchIndex):
    text = indexes.CharField(document=True, use_template=True)
    creator = indexes.CharField(model_attr='creator')
    created = indexes.DateTimeField(model_attr='created')
    title = indexes.DateTimeField(model_attr='title')
    url = indexes.DateTimeField(indexed=False, use_template=True)

    def get_queryset(self):
        "Used when the entire index for model is updated."
        return News.objects.filter(active=True)


site.register(News, NewsIndex)
